.SUFFIXES: .asm

# defines
MAKEFILE=linux.mak
MAKEDEP=$(MAKEFILE)
INCDIR	=inc
LDSCRIPT=krnl1m.ld
NASM	=nasm -f elf -i./$(INCDIR)/
CC	=gcc -g -Wall -W -O2 -nostdinc -fno-builtin -I./$(INCDIR)
LD	=ld -g -T $(LDSCRIPT) -nostdlib
LIBC	=lib/libc.a
OBJS	=src/kstart.o src/video.o src/debug.o src/kbd.o src/sched.o src/tasks.o src/main.o

# targets
all: kernel

clean:
	rm -f src/*.o kernel krnl.sym krnl.lst

# implicit rules
.asm.o:
	$(NASM) -o$@ $<

.c.o:
	$(CC) -c -o$@ $<

# dependencies
kstart.o:	src/kstart.asm

main.o:		src/main.c

video.o:	src/video.c

debug.o:	src/debug.c

kbd.o:		src/kbd.c

sched.o:	src/sched.c

tasks.o:	src/tasks.c

# explicit rules
$(LIBC): lib/$(MAKEFILE)
	make -C lib -f $(MAKEFILE)

kernel: $(OBJS) $(LDSCRIPT) $(LIBC)
	$(LD) -o$@ $(OBJS) $(LIBC)
	objdump --source $@ >krnl.lst
	nm $@ | sort >krnl.sym
	strip $@
